package com.car.mgr.web.qdsl.utils;

import java.io.Serializable;
import java.util.List;
import lombok.Builder;
import lombok.Data;
import org.springframework.data.domain.Page;

@Builder
@Data
public class PageResult<T> implements Serializable {
  private final int totalPage;

  private final long totalElement;

  private final int perPageSize;

  private final int pageNumber;

  private final List<T> content;

  public static <T> PageResult toPageResult(Page<T> page) {
    return PageResult.<T>builder().totalPage(page.getTotalPages()).pageNumber(page.getNumber()).totalElement(page.getTotalElements()).perPageSize(page.getSize()).content(page.getContent()).build();
  }
}
